﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FinanSoft.Entities;

namespace  FinanSoft.Entities

{
    public class AccountingPeriod
    {

        #region Constructors
        /// <summary>
        /// Constructor de la clase. Recibe parametros para todos los atributos del periodo
        /// </summary>
        public AccountingPeriod(int id, int mode, string name, DateTime sdate, DateTime edate, Season[] seasons)
        {
            this.Id = id;
            this.Type = mode;
            this.Name = name;
            this.StartDate = sdate;
            this.EndDate = edate;
            this.Seasons = seasons;
            
        }

        /// <summary>
        /// Constructor por defecto de la clase
        /// </summary>
        public AccountingPeriod()
        {
           // throw new System.NotImplementedException();
        }
        #endregion

        #region Properties
        /// <summary>
        /// Entero que identifica de manera unica al periodo
        /// </summary>
        public int Id
        {
            get;
            set;
        }

        /// <summary>
        /// String con el nombre del periodo
        /// </summary>
        public String Name
        {
            get;
            set;
        }

        /// <summary>
        /// Fecha de inicio del periodo
        /// </summary>
        public DateTime StartDate
        {
            get;
            set;
        }

        /// <summary>
        /// Fecha de cierre del periodo
        /// </summary>
        public DateTime EndDate
        {
            get;
            set;
        }

        /// <summary>
        /// Arreglo con las temporadas que componen el periodo
        /// </summary>
        public Season[] Seasons
        {
            get;
            set;
        }

        /// <summary>
        /// Modo del periodo
        /// </summary>
        public int Type
        {
            get;
            set;
        }
        #endregion

        public Season GetLastSeason()
        {
            Season lastSeason = new Season();
            lastSeason.EndDate = new DateTime(1900, 1, 1);
            foreach (Season season in Seasons)
                if (season.EndDate > lastSeason.EndDate)
                    lastSeason = season;
            return lastSeason;
        }

        public Season GetCurrentSeason()
        {
            DateTime today = DateTime.Now;
            foreach (Season season in Seasons)
                if (season.EndDate >= today && season.StartDate <= today)
                    return season;
            return null;
        }
    }
}
